package com.xn.app.muying.BroadcastReceiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.widget.Toast;

/**
 * 网络监听广播
 * Created by gaoge on 2016/11/17.
 */

public class NetworkConnectChangedReceiver extends BroadcastReceiver {

    public void onReceive(Context context, Intent intent) {

        ConnectivityManager connectivityManager = (ConnectivityManager)
                context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
        if (networkInfo != null && networkInfo.isAvailable()) {
            Toast.makeText(context, "有网络", Toast.LENGTH_SHORT).show();
            context.sendBroadcast(new Intent("bei_er").putExtra("bei_er",0));
        } else {
        }
    }
}
